package kr.saeildamil.androidforstudy2.ch28;

import android.app.Activity;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.widget.LinearLayout.LayoutParams;
import android.widget.ScrollView;
import android.widget.TextView;

public class ConMgr extends Activity {
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		ScrollView root = new ScrollView(this);
		LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
		root.setLayoutParams(params);
		TextView tv = new TextView(this);
		tv.setLayoutParams(params);
		
		root.addView(tv);
		
		setContentView(root);
		
		StringBuilder sb = new StringBuilder();
		ConnectivityManager mgr = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
		
		NetworkInfo[] ani = mgr.getAllNetworkInfo();
		
		for(NetworkInfo net : ani){
			sb.append(net.toString() + "\n"); 
		}
		
		NetworkInfo net02 = mgr.getActiveNetworkInfo();
		
		if(net02 != null){
			sb.append("Active : \n" + net02.toString() + "\n");
			tv.setText(sb);
		}
	}

}
